<?php

/**
 * MVM_MALL 网上商店系统  界面风格管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-07-15 $
 * $Id: setstyles.inc.php www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
     /**css风格变量值**/
        $styles_list = array(
        array('name' => 'bgcolor',   'value' => '#ffffff','label'=>$lang['bgcolor']),
        array('name' => 'wordcolor', 'value' => '#585858','label'=>$lang['wordcolor']),
        array('name' => 'linkcolor', 'value' => '#585858','label'=>$lang['linkcolor']),
        array('name' => 'hoverlink', 'value' => '#ff6600','label'=>$lang['hoverlink']),
        array('name' => 'topbackground', 'value' => 'top1.jpg','label'=>$lang['topbackground']),
        array('name' => 'navbackground', 'value' => 'top2.jpg','label'=>$lang['navbackground']),
        array('name' => 'lbackground', 'value' => 'top3.jpg','label'=>$lang['lbackground']),
        array('name' => 'gbackground', 'value' => 'top4.jpg','label'=>$lang['gbackground']),
        array('name' => 'titlecolor', 'value' => '#585858','label'=>$lang['titlecolor']),
        array('name' => 'titlebg', 'value' => 'title_bg.jpg','label'=>$lang['titlebg']),
        array('name' => 'bordercolor', 'value' => '#c4e6af','label'=>$lang['bordercolor']),
        array('name' => 'qbordercolor', 'value' => '#deead2','label'=>$lang['qbordercolor']),
        array('name' => 'qbgcolor', 'value' => '#f3f8ef','label'=>$lang['qbgcolor']),
        array('name' => 'stitlecolor', 'value' => '#659b28','label'=>$lang['stitlecolor']),
        array('name' => 'ancolor', 'value' => '#ffffff','label'=>$lang['ancolor']),
        array('name' => 'jgcolor', 'value' => '#ff0000','label'=>$lang['jgcolor']),
        array('name' => 'imgbordercolor', 'value' => '#cccccc','label'=>$lang['imgbordercolor']),
        array('name' => 'xxbackground', 'value' => 'tableheader.gif','label'=>$lang['xxbackground']),
        );
                     
/**显示风格列表**/
if($action=='list') {
    $styles = array();
    $result =$db->query("SELECT * FROM {$tablepre}styles");
    while($rt=$db->fetch_array($result)){
        $rt['available'] = $rt['available'] ? $lang['yes'] : $lang['no'];
        $rt['tplpath']   = $rt['tplpath'];
        $rt['edit']      = "admincp.php?module=$module&action=edit&uid=$rt[uid]";
        $rt['del']       = "admincp.php?module=$module&action=del&uid=$rt[uid]";
        $style_rt[]      = $rt;
    }
    require_once template('setstyles');
    footer();
}

/**添加风格**/
elseif ($action=='add' || $action=='edit' ) {
    if($setp==1 && $_POST){
        $style_name = trim(dhtmlchars($style_name));
        $tplpath   = trim(dhtmlchars($tplpath));
        foreach ($styles_list AS $key => $val)
        {
            $styles_array[$key]['name']   = $val['name'];
            $styles_array[$key]['value']  = $$val['name'];
            $styles_array[$key]['label']  = $val['label'];
        }
        @extract($styles_array);
        $styles_array = serialize(dhtmlchars($styles_array));
        $row = array(
        'name'     =>$style_name,
        'available'=> $available,
        'tplpath'  => $tplpath,
        'config'   => $styles_array
        );
        if($action=='add'){
            $uid = $db->insert("{$tablepre}styles",$row);
        }elseif ($action=='edit' && is_numeric($uid)){
            $where = "uid='$uid'";
            $db->update("{$tablepre}styles",$row,$where);
        }
        /**生成css**/
        require_once template('css');
        $date = clean_html('red');
	    writeover("data/style/style_$uid.css",$date);
	    $cache->put_cache('style');
        admin_msg('success',"admincp.php?module=$module&action=list");
    }else{
        if ($action=='edit' && is_numeric($uid)) {
            $rt            = $db->get_one("SELECT * FROM `{$tablepre}styles` WHERE uid='$uid'");
            $styles_list   = unserialize($rt['config']);
            @extract($rt,EXTR_OVERWRITE);
            $available==1 ? $use_chk = 'checked' : $uset_chk= 'checked';
        }else {
            $use_chk = 'checked';
        }
        $tplpath_menu = drop_menu(tpl_array(),'tplpath',$tplpath);
        require_once template('setstyles_add');
        footer();
    }
}
/*删除风格**/
elseif ($action=='del' && is_numeric($uid)) {
    file_unlink(MVMMALL_ROOT."./data/style/style_$uid.css");
    $db->query("DELETE FROM `{$tablepre}styles` WHERE uid='$uid'");
    $cache->put_cache('style');
}

else {
    admin_msg('pass_worng');
}

